<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>添加URL重写器的值（Add URL rewriter values）</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.ob-start.html">« ob_start</a></li>
      <li style="float: right;"><a href="function.output-reset-rewrite-vars.html">output_reset_rewrite_vars »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.outcontrol.html">Output Control 函数</a></li>
    <li>添加URL重写器的值（Add URL rewriter values）</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.output-add-rewrite-var" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">output_add_rewrite_var</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">output_add_rewrite_var</span> &mdash; <span class="dc-title">添加URL重写器的值（Add URL rewriter values）</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.output-add-rewrite-var-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>output_add_rewrite_var</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$value</code></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   此函数给URL重写机制添加名/值对。
   这种名值对将被添加到 URL（以 GET 参数的形式）和表单（以 input 隐藏域的形式），当透明 URL 重写用 
   <a href="session.configuration.html#ini.session.use-trans-sid" class="link">session.use_trans_sid</a>
   开启时同样可以添加到 session ID。
  </p>
  <p class="para">
   此函数的行为受 <a href="outcontrol.configuration.html#ini.url-rewriter.tags" class="link">url_rewriter.tags</a> 和
   <a href="outcontrol.configuration.html#ini.url-rewriter.hosts" class="link">url_rewriter.hosts</a> <var class="filename">php.ini</var> 参数控制。
  </p>
  <p class="para">
   注意，每个请求最多可以成功调用此函数一次。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    如果还没有活跃的输出缓冲区，调用此函数将隐式地开启它。
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.output-add-rewrite-var-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">name</code></dt>

     <dd>

      <p class="para">
       变量名。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">value</code></dt>

     <dd>

      <p class="para">
       变量值。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.output-add-rewrite-var-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.output-add-rewrite-var-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.1.0</td>
       <td>
        在 PHP 7.1.0 之前，使用 <span class="function"><strong>output_add_rewrite_var()</strong></span> 设置重写变量使用相同的
        Session 模块 trans sid 输出缓冲区。从 PHP 7.1.0 起，使用专用的输出缓冲区，<a href="outcontrol.configuration.html#ini.url-rewriter.tags" class="link">
        url_rewriter.tags</a> 仅用于输出函数，新增 <a href="outcontrol.configuration.html#ini.url-rewriter.tags" class="link">url_rewriter.hosts</a>。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.output-add-rewrite-var-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-544">
    <p><strong>示例 #1 <span class="function"><strong>output_add_rewrite_var()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />output_add_rewrite_var</span><span style="color: #007700">(</span><span style="color: #DD0000">'var'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'value'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;some&nbsp;links<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'&lt;a&nbsp;href="file.php"&gt;link&lt;/a&gt;<br />&lt;a&nbsp;href="http://example.com"&gt;link2&lt;/a&gt;'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;a&nbsp;form<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'&lt;form&nbsp;action="script.php"&nbsp;method="post"&gt;<br />&lt;input&nbsp;type="text"&nbsp;name="var2"&nbsp;/&gt;<br />&lt;/form&gt;'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">ob_list_handlers</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
&lt;a href=&quot;file.php?var=value&quot;&gt;link&lt;/a&gt;
&lt;a href=&quot;http://example.com&quot;&gt;link2&lt;/a&gt;

&lt;form action=&quot;script.php&quot; method=&quot;post&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;var&quot; value=&quot;value&quot; /&gt;
&lt;input type=&quot;text&quot; name=&quot;var2&quot; /&gt;
&lt;/form&gt;

Array
(
    [0] =&gt; URL-Rewriter
)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.output-add-rewrite-var-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.output-reset-rewrite-vars.html" class="function" rel="rdfs-seeAlso">output_reset_rewrite_vars()</a> - 重设URL重写器的值（Reset URL rewriter values）</span></li>
    <li class="member"><span class="function"><a href="function.ob-flush.html" class="function" rel="rdfs-seeAlso">ob_flush()</a> - 冲刷出（送出）输出缓冲区中的内容</span></li>
    <li class="member"><span class="function"><a href="function.ob-list-handlers.html" class="function" rel="rdfs-seeAlso">ob_list_handlers()</a> - 列出所有使用的输出处理程序</span></li>
    <li class="member"><a href="outcontrol.configuration.html#ini.url-rewriter.tags" class="link">url_rewriter.tags</a></li>
    <li class="member"><a href="outcontrol.configuration.html#ini.url-rewriter.hosts" class="link">url_rewriter.hosts</a></li>
    <li class="member"><a href="session.configuration.html#ini.session.trans-sid-tags" class="link">session.trans_sid_tags</a></li>
    <li class="member"><a href="session.configuration.html#ini.session.trans-sid-hosts" class="link">session.trans_sid_hosts</a></li>
   </ul>
  </p>
 </div>
  

</div></div></div></body></html>